package xyz.ddlnt.servicemq.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import xyz.ddlnt.commonutil.constant.FieldConstants;
import xyz.ddlnt.commonutil.util.RandomUtil;
import xyz.ddlnt.model.entity.Message;
import xyz.ddlnt.servicemq.mapper.MessageMapper;
import xyz.ddlnt.servicemq.service.MessageService;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/26 16:55
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {
    @Resource
    private MessageMapper messageMapper;

    @Override
    public void messagePlusOne(Map<String, String> map) {
        Message message = Message.builder()
                .id(RandomUtil.generate12DigitRandomNumber())
                .senderId(Long.parseLong(map.get(FieldConstants.SENDER_ID)))
                .receiverId(Long.parseLong(map.get(FieldConstants.RECEIVER_ID)))
                .isImg(Boolean.parseBoolean(map.get(FieldConstants.IS_IMG)))
                .content(map.get(FieldConstants.CONTENT))
                .sendTime(LocalDateTime.parse(map.get(FieldConstants.SEND_TIME)))
                .sender_version(Integer.parseInt(map.get(FieldConstants.SENDER_VERSION)))
                .receiver_version(Integer.parseInt(map.get(FieldConstants.RECEIVER_VERSION)))
                .build();
        messageMapper.insert(message);
    }
}
